 venv:
	python -m venv .venv;source .venv/bin/activate 

install:
	pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

install-dev: install
	pip install -e ".[dev]"

docker-install:
	pip install --no-index --trusted-host packagedownloads -f http://packagedownloads:8000/ -r requirements.txt

docker-install-dev: docker-install
	pip install --no-index --trusted-host packagedownloads -f http://packagedownloads:8000/ -e '.[dev]'

package-downloads:
	mkdir -p packagedownloads
	pip download -d packagedownloads -r requirements.txt '.[dev]'
	# If running in docker-compose directory will be root, so make easy for
	# other users to clean up.
	chmod -R go+w packagedownloads

lint:
	flake8 app tests config

unit:
	pytest -sv tests/unit

component:
	pytest -sv tests/component

coverage:
	coverage run -m pytest tests/unit tests/component --junitxml=build/test.xml -v
	coverage report --fail-under=90
	coverage xml -i -o build/coverage.xml

test: lint unit component

run:
	uvicorn app_loader:app --reload --host 0.0.0.0  --port 8080
# gunicorn --config config/gunicorn/gunicorn.py app_loader:app

run-dev:
	# Run application with 1 worker with hot-reload enabled
	python run_local_server.py
	
# gunicorn --config config/gunicorn/gunicorn.py -w1 --reload app_loader:app

freeze:
	CUSTOM_COMPILE_COMMAND="make freeze" pip-compile --no-annotate --no-emit-index-url --output-file requirements.txt setup.py

docker-freeze:
	CUSTOM_COMPILE_COMMAND="make freeze" pip-compile --trusted-host packagedownloads -f http://packagedownloads:8000/ --no-annotate --no-emit-index-url --no-emit-find-links --no-emit-trusted-host --output-file requirements.txt setup.py

deps-check: docker-freeze
	git diff --exit-code -- requirements.txt

freeze-upgrade:
	CUSTOM_COMPILE_COMMAND="make freeze" pip-compile --no-annotate --no-emit-index-url --upgrade --output-file requirements.txt setup.py

.PHONY: install install-dev lint unit component coverage test run run-dev freeze freeze-upgrade docker-install docker-install-dev package-downloads deps-check docker-freeze
